import React, {Component} from 'react';
import {View, Text,StyleSheet,Platform,BackAndroid} from  'react-native';
import {IndicatorViewPager,PagerTitleIndicator} from 'rn-viewpager';
import Icon from 'react-native-vector-icons/FontAwesome';
export default class GoodDetail extends Component{
    constructor(props){
        super(props);
        this.state={};
        this.back=this.back.bind(this)
    }
    render(){
        return(
            <IndicatorViewPager
                style={{flex: 1, flexDirection: 'column-reverse'}}
                indicator={this._renderTitleIndicator()}
            >
                <View style={{backgroundColor:'cadetblue'}}>
                    <Text>page one</Text>
                </View>
                <View style={{backgroundColor:'cornflowerblue'}}>
                    <Text>page two</Text>
                </View>
                <View style={{backgroundColor:'#1AA094'}}>
                    <Text>page three</Text>
                </View>
            </IndicatorViewPager>
        )
    }

    _renderTitleIndicator() {
        return (
            <PagerTitleIndicator titles={['商品', '详情', '评价']}/>
        )
    }
    componentWillMount () {
        if (Platform.OS === 'android') {
            BackAndroid.addEventListener('hardwareBackPress', this.back);
        }
    }

    componentWillUnmount(){
        if (Platform.OS === 'android') {
            BackAndroid.removeEventListener('hardwareBackPress', this.back);
        }
    }
    back(){
        this.props.navigation.goBack();
        return true;
    }
    static navigationOptions = ({navigation}) => ({
        title: navigation.state.params.title,
    });
}